package com.sk.bilibili.utils;

import com.sk.bilibili.api.LiveApi;
import com.sk.bilibili.bean.Live;
import com.sk.bilibili.bean.LiveType;
import com.sk.bilibili.dto.LiveData;
import com.sk.bilibili.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author 邵康
 * @date 2021/11/26 16:01
 */
@Component
public class WarpUtils {

    @Autowired
    private LiveService liveService;
    @Autowired
    private VideoSetService videoSetService;
    @Autowired
    private ThemService themService;
    @Autowired
    private NoteService noteService;
    @Autowired
    private ForwardService forwardService;

    public Live warpLive(LiveData item) {
        Live live = liveService.getRandomLive();
        BeanUtils.copyProperties(item, live);
        live.getExtra().put("roomId",item.getRoomid());//需要通过  是否有roomId  判断是否为B站直播 进行获取直播链接
//        live.setUrl(liveApi.getLiveUrl(item.getRoomid()));// 先不获取URL  使用时再获取  否则容易封IP
        ((LiveType) live.getExtra().get("liveType")).setTitle(item.getLiveType());
        Object member = live.getExtra().get("member");
        BeanUtils.copyProperties(item, member);
        return live;
    }

    public Object getTypeTarget(Integer type, Integer targetId) {
        switch (type) {
            case 0:
                return videoSetService.getBaseVideoSet(targetId);
            case 1:
                return themService.getWarpThem(targetId);
            case 2:
                return noteService.getWarpNote(targetId);
            case 5:
                return forwardService.getWarpForward(targetId);
            case 6:
                return liveService.getFullLive(targetId);
            default:
                throw new RuntimeException("错误的类型:" + type);
        }
    }

}
